import { DataSource } from 'typeorm';

import { Template } from './entity/template.entity';
import { TemplateCategory } from './entity/template-category.entity';
import { User } from './entity/user.entity';
import { FileEntity } from './entity/file.entity';
import { SysConfig } from './entity/sys_config.entity';
import { ChargeRecord } from './entity/charge_record.entity';
import { Category } from './entity/category.entity';
import { Order } from './entity/order.entity';
import { Work } from './entity/work.entity';
import { Collection } from './entity/collection.entity';
import { QrCodeEntity } from './entity/qrcode.entity';
import { CommonEntity } from './entity/common.entity';
import { ChatRoomEntity } from './entity/chat_room.entity';
import { UserFileEntity } from './entity/user_file.entity';
import { ChatSceneEntity } from './entity/chat_scene.entity';
import { ChatRoundEntity } from './entity/chat_round.entity';
export const databaseProviders = [
  {
    provide: 'DATA_SOURCE',
    useFactory: async () => {
      const dataSource = new DataSource({
        type: 'mysql',
        host: process.env.DB_HOST,
        port: Number(process.env.DB_PORT),
        username: process.env.DB_USER,
        password: process.env.DB_PASSWORD,
        database: process.env.DB_DATABASE,
        entities: [
          Template,
          TemplateCategory,
          User,
          FileEntity,
          SysConfig,
          ChargeRecord,
          Category,
          Order,
          Work,
          Collection,
          QrCodeEntity,
          CommonEntity,
          ChatRoomEntity,
          UserFileEntity,
          ChatSceneEntity,
          ChatRoundEntity,
        ],
        dateStrings: true,
        timezone: '+08:00',
        synchronize: true,
        // logging: ["query", "error"]
        logging: ["error"]
      });

      return dataSource.initialize();
    },
  },
];
